<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
	<c:choose>
		<c:when test="${mode == 'u'}">
			<c:url value="bbs_modify.action" var="URL"/>
		</c:when>
		<c:when test="${mode == 'r'}">
			<c:url value="bbs_reply.action" var="URL"/>
		</c:when>
		<c:otherwise>
			<c:url value="bbs_write.action" var="URL"/>
		</c:otherwise>
	</c:choose>
	<h3>쓰기</h3>
	<script type="text/javascript">
	$(function(){
		$("form[name='bbs_form']").validate({
			rules:{
				title:"required",
				writer:"required",
				content:"required"
			},
			messages:{
				title:"제목을 입력하세요",
				writer:"이름을 입력하세요",
				content:"글을 입력하세요"
			}	
		});
		$(".addFile").click(function(){
			if($(".files").size() > 2){
				alert("3개이상 추가 불가능");
				return;
			}
			var Html = 
				"<tr class=\"files\">"+
					"<th>파일</th>"+
					"<td colspan=\"3\"><input type=\"file\" name=\"uploads\"/> &nbsp;&nbsp;&nbsp;"+
					"<input type=\"button\" value=\"삭제\" class=\"button fileDel\"   "+
					"</td>"+
				"</tr>";
			$("#content").before(Html);
			$(".fileDel").bind('click',function(){
				$(this).parents('tr').remove();
			});
		});
	});
	
	</script>
	
	<form method="post" action="${URL}" name="bbs_form" enctype="multipart/form-data">
	<input type="hidden" name="currentPage" value="${currentPage}"/>
	<input type="hidden" name="bname" value="${bname}"/>
	<input type="hidden" name="seq" value="${boardVo.seq}"/>
	<input type="hidden" name="groups" value="${boardVo.groups}"/>
	<input type="hidden" name="step" value="${boardVo.step}"/>
	<input type="hidden" name="depth" value="${boardVo.depth}"/>
	<table border="1" cellspacing="0" width="100%" class="bbs">
	<tbody>
		<tr>
			<th align="center" width="100"><label for="title">제목</label></th>
			<td><input type="text" id="title" name="title" value="${boardVo.title}"/></td>
			<th align="center" width="100"><label for="writer">글쓴이</label></th>
			<td><input type="text" id="writer" name="writer" value="${boardVo.writer}"/></td>
		</tr>
		<tr class="files">
			<th>파일</th>
			<td colspan="3">
				<input type="file" name="uploads"/> &nbsp;&nbsp;&nbsp;
				<input type="button" value="추가" class="button addFile"/>
			</td>
		</tr>
		<tr id="content">
			<td colspan="4">
			<p class="contents">
				<strong><label for="content">내용</label></strong>
			</p>
			<p class="contents">
				<textarea id="content" name="content" style="width:700px;height:200px;">${boardVo.content}</textarea>
			</p>
			</td>
		</tr>
	</tbody>
	<tfoot>
		<tr>
			<td align="right" colspan="4">
				<input type="submit" class="button" value="확인"/>
				<input type="button" class="button" value="목록" onclick="location.href='bbs.action?bname=${bname}&currentPage=${currentPage}'"/>
			</td>
		</tr>
	</tfoot>
	</table>
	</form>